define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wallet/index' + location.search,
                    add_url: 'wallet/add',
                    edit_url: 'wallet/edit',
                    del_url: 'wallet/del',
                    multi_url: 'wallet/multi',
                    import_url: 'wallet/import',
                    table: 'wallet',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'status_switch', title: __('Status_switch'), searchList: {"1":__('Status_switch 1'),"-1":__('Status_switch -1'),"-2":__('Status_switch -2')}, table: table, formatter: Table.api.formatter.toggle},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'before', title: __('Before'), operate:'BETWEEN'},
                        {field: 'after', title: __('After'), operate:'BETWEEN'},
                        {field: 'memo', title: __('Memo'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate: 'LIKE'},
                        {field: 'updatetime', title: __('Updatetime'), operate: 'LIKE'},
                        {field: 'usertable.id', title: __('Usertable.id')},
                        {field: 'usertable.pid', title: __('Usertable.pid')},
                        {field: 'usertable.real_name', title: __('Usertable.real_name'), operate: 'LIKE'},
                        {field: 'usertable.username', title: __('Usertable.username'), operate: 'LIKE'},
                        {field: 'usertable.nickname', title: __('Usertable.nickname'), operate: 'LIKE'},
                        {field: 'usertable.password', title: __('Usertable.password'), operate: 'LIKE'},
                        {field: 'usertable.salt', title: __('Usertable.salt'), operate: 'LIKE'},
                        {field: 'usertable.pay_password', title: __('Usertable.pay_password'), operate: 'LIKE'},
                        {field: 'usertable.pay_salt', title: __('Usertable.pay_salt'), operate: 'LIKE'},
                        {field: 'usertable.idcard', title: __('Usertable.idcard'), operate: 'LIKE'},
                        {field: 'usertable.email', title: __('Usertable.email'), operate: 'LIKE'},
                        {field: 'usertable.mobile', title: __('Usertable.mobile'), operate: 'LIKE'},
                        {field: 'usertable.avatar', title: __('Usertable.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'usertable.level_id', title: __('Usertable.level_id')},
                        {field: 'usertable.gender', title: __('Usertable.gender')},
                        {field: 'usertable.birthday', title: __('Usertable.birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'usertable.bio', title: __('Usertable.bio'), operate: 'LIKE'},
                        {field: 'usertable.money', title: __('Usertable.money'), operate:'BETWEEN'},
                        {field: 'usertable.score', title: __('Usertable.score'), operate:'BETWEEN'},
                        {field: 'usertable.ten_prize_money', title: __('Usertable.ten_prize_money'), operate:'BETWEEN'},
                        {field: 'usertable.invite_code', title: __('Usertable.invite_code'), operate: 'LIKE'},
                        {field: 'usertable.invitation_num', title: __('Usertable.invitation_num')},
                        {field: 'usertable.today_active', title: __('Usertable.today_active'), operate:'BETWEEN'},
                        {field: 'usertable.last_active', title: __('Usertable.last_active'), operate:'BETWEEN'},
                        {field: 'usertable.is_nine', title: __('Usertable.is_nine')},
                        {field: 'usertable.is_ten', title: __('Usertable.is_ten')},
                        {field: 'usertable.is_effect', title: __('Usertable.is_effect')},
                        {field: 'usertable.effect_user', title: __('Usertable.effect_user')},
                        {field: 'usertable.prize_total', title: __('Usertable.prize_total')},
                        {field: 'usertable.alerday_pin_total', title: __('Usertable.alerday_pin_total')},
                        {field: 'usertable.group_num', title: __('Usertable.group_num')},
                        {field: 'usertable.group_num_all', title: __('Usertable.group_num_all')},
                        {field: 'usertable.today_prize', title: __('Usertable.today_prize'), operate:'BETWEEN'},
                        {field: 'usertable.all_prize', title: __('Usertable.all_prize'), operate:'BETWEEN'},
                        {field: 'usertable.successions', title: __('Usertable.successions')},
                        {field: 'usertable.maxsuccessions', title: __('Usertable.maxsuccessions')},
                        {field: 'usertable.openid', title: __('Usertable.openid'), operate: 'LIKE'},
                        {field: 'usertable.prevtime', title: __('Usertable.prevtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'usertable.logintime', title: __('Usertable.logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'usertable.loginip', title: __('Usertable.loginip'), operate: 'LIKE'},
                        {field: 'usertable.loginfailure', title: __('Usertable.loginfailure')},
                        {field: 'usertable.joinip', title: __('Usertable.joinip'), operate: 'LIKE'},
                        {field: 'usertable.jointime', title: __('Usertable.jointime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'usertable.createtime', title: __('Usertable.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'usertable.updatetime', title: __('Usertable.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'usertable.token', title: __('Usertable.token'), operate: 'LIKE'},
                        {field: 'usertable.status_switch', title: __('Usertable.status_switch'), table: table, formatter: Table.api.formatter.toggle},
                        {field: 'usertable.verification', title: __('Usertable.verification'), operate: 'LIKE'},
                        {field: 'usertable.state', title: __('Usertable.state')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});